package com.iterator.service.wechat.wy.catalog;

import com.iterator.bean.wechat.wy.catalog.CurrentVO;
import com.iterator.bean.wechat.wy.catalog.IndexVO;
import com.iterator.bean.wechat.wy.catalog.WxCatalog;
import com.iterator.mapper.wechat.wy.catalog.WxCatalogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Silence_W
 * @date: 2021-01-12 16:15
 **/
@Service
public class WXCatalogServiceImpl implements WXCatalogService {
    @Autowired
    WxCatalogMapper wxCatalogMapper;

    @Override
    public IndexVO queryCatalog() {

        List<WxCatalog> catalogs = wxCatalogMapper.selectCatalogByLevel("L1");
        List<WxCatalog>  go= new ArrayList<>();
        for (WxCatalog catalog : catalogs) {
            Integer id = catalog.getId();
            List<WxCatalog>  goo = wxCatalogMapper.selectCataById(id);
            go.addAll(goo);
        }
        return new IndexVO(catalogs.get(0),catalogs,go);
    }

    @Override
    public CurrentVO queryCurrentCatalog(Integer id) {
        WxCatalog wxCatalog= wxCatalogMapper.selectCatalogById(id);
        List<WxCatalog> catalogs = wxCatalogMapper.selectCataById(wxCatalog.getId());

        return new CurrentVO(wxCatalog,catalogs);
    }
}
